package com.ksyun.whyc.xiongyu.xuesheng;

import java.lang.annotation.*;
import java.lang.reflect.*;
import java.util.*;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@interface StudentAnnotation {
    String value();
}

class Student {
    @StudentAnnotation("姓名")
    public String name;

    @StudentAnnotation("年龄")
    public int age;

    @StudentAnnotation("住址")
    public String address;

    @StudentAnnotation("出生年月")
    public String birthday;

    public Student(String name, int age, String address, String birthday) {
        this.name = name;
        this.age = age;
        this.address = address;
        this.birthday = birthday;
    }
}
public class StudentCollection {
    public static void main(String[] args) {
        List<Student> students = new ArrayList<Student>();
        students.add(new Student("张三", 20, "北京市海淀区", "1990-01-01"));
        students.add(new Student("李四", 21, "北京市朝阳区", "1991-02-02"));
        students.add(new Student("王五", 22, "北京市东城区", "1992-03-03"));

        Field[] fields = Student.class.getDeclaredFields();

        for (Field field : fields) {
            if (field.isAnnotationPresent(StudentAnnotation.class)) {
                System.out.print(field.getAnnotation(StudentAnnotation.class).value() + "\t");
            }
        }

        System.out.println();

        for (Student student : students) {
            for (Field field : fields) {
                if (field.isAnnotationPresent(StudentAnnotation.class)) {
                    try {
                        System.out.print(field.get(student) + "\t");
                    } catch (IllegalAccessException e) {
                        e.printStackTrace();
                    }
                }
            }

            System.out.println();
        }
    }
}
